<template>
  <el-row>
    <el-col>
      <basic-container>
        <avue-crud :option="option"
                   :table-loading="loading"
                   :data="data"
                   :page="page"
                   :permission="permissionList"
                   :before-open="beforeOpen"
                   v-model="form"
                   ref="crud"
                   @row-update="rowUpdate"
                   @row-save="rowSave"
                   @row-del="rowDel"
                   @search-change="searchChange"
                   @search-reset="searchReset"
                   @selection-change="selectionChange"
                   @current-change="currentChange"
                   @size-change="sizeChange"
                   :upload-error="loadError"
                   @on-load="onLoad" v-if="showMain">
          <template slot="menuLeft">
            <el-button type="danger"
                       size="small"
                       icon="el-icon-delete"
                       plain
                       v-if="permission.job_delete"
                       @click="handleDelete">删 除
            </el-button>
          </template>

          <template slot-scope="{type,size,row,index}"  slot="menuBtn">
            <el-dropdown-item divided @click.native="showJobRecords(row,index)">作业情况</el-dropdown-item>
          </template>
        </avue-crud>
        <Jobrecords v-bind:jobId="jobId"  :showMainView="showMainView" v-if="(!showMain)" ref="eps1"></Jobrecords>

      </basic-container>
    </el-col>
  </el-row>

</template>

<script>
  import {getList, add, update, remove,GradesByTeacher,CourseListByTeacher,GetWorkTypeList,getTeacherByRelateId} from "@/api/service/job";
  import {mapGetters} from "vuex";
  import Jobrecords from "@/views/service/jobrecords";
  import {selectImgId} from "@/api/service/tz";
  import {contrastTime} from "@/util/validate";

  export default {
    components:{
      Jobrecords
    },
    data() {
      return {
        treeBj:'0',
        // treeData: [],
        treeOption: {
          nodeKey: 'id',
          lazy: false,
          addBtn: false,
          menu: false,
          size: 'small',
          defaultExpandAll:true,
          props: {
            labelText: '标题',
            label: 'title',
            value: 'value',
            children: 'children'
          }
        },
        jobId:"",
        showMain:true,
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height: 'auto',
          calcHeight: 210,
          searchShow: true,
          searchMenuSpan: 6,
          tip: false,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          dialogWidth:"70%",
          menuType:'menu',
          menuBtnTitle:'更多操作',
          column: [
            {
              label: "主键",
              prop: "id",
              rules: [{
                required: true,
                message: "请输入主键",
                trigger: "blur"
              }],
              hide:true,
              display:false
            },
            {
              label: "学校",
              prop: "schoolName",
              rules: [{
                required: false,
                message: "请输入学校名称",
                trigger: "blur"
              }],
              // type: "select",
              // dicUrl: "/api/PcPublicService/GetSelectSchoolList",
              // props: {
              //   label: "xxName",
              //   value: "id"
              // },
              editDisabled: true,
              addDisabled: true
            },
            {
              label: "教师",
              prop: "jsName",
              search: false,
              overHidden: true,
              rules: [{
                required: true,
                message: "请输入教师姓名",
                trigger: "blur"
              }],
              // type: "select",
              // dicUrl: "/api/school-service/js/select",
              // props: {
              //   label: "jsName",
              //   value: "id"
              // },
              // dataType: "number",
              editDisabled: true,
              addDisabled: true,
            },
            {
              label: "班级",
              prop: "bjId",
              search:true,
              rules: [{
                required: true,
                message: "请输入班级",
                trigger: "blur"
              }],
              nodeClick:(data, node)=>{
                this.form.bjName = node.data.name
                // this.form.xnId = node.data.xnId;
                // this.form.njId = node.data.njId;

              },
              type: "tree",
              dicData: [],
              props: {
                label: "name",
                value: "id"
              },
              slot: true,
              checkStrictly: true,
              editDisabled:true,
            },
            {
              label: "课程",
              search:true,
              prop: "kcId",
              rules: [{
                required: true,
                message: "请选择课程",
                trigger: "blur"
              }],
              type: "select",
              dicData:[],
              props: {
                label: "title",
                value: "id"
              },
              nodeClick:(data, node)=>{
                console.log(node)
                // this.form.kcName = node.data.couresName
                // this.form.xnId = node.data.xnId;
                // this.form.njId = node.data.njId;

              },
              editDisabled:true,
              //addDisabled:true
            },
            {
              label: "作业类型",
              prop: "jobType",
              rules: [{
                required: true,
                message: "请输入完成地点",
                trigger: "blur"
              }],
              type: "select",
              dicData: [],
              props: {
                label: "name",
                value: "id"
              },
            },
            {
              label: "开始时间",
              search:true,
              prop: "startTime",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              valueFormat: "yyyy-MM-dd HH:mm",
              overHidden:true,
              rules: [{
                required: true,
                message: "请输入开始时间",
                trigger: "blur"
              }]
            },
            {
              label: "结束时间",
              search:true,
              prop: "endTime",
              type: "datetime",
              format: "yyyy-MM-dd HH:mm",
              valueFormat: "yyyy-MM-dd HH:mm",
              overHidden:true,
              rules: [{
                required: true,
                message: "请输入结束时间",
                trigger: "blur"
              }]
            },
            {
              label: "预计时长",
              prop: "hour",
              rules: [{
                required: true,
                message: "请输入预计时长",
                trigger: "blur"
              }],
              type: "number",
            },
            // {
            //   label: "实际时长",
            //   prop: "jobRealTime",
            //   rules: [{
            //     required: false,
            //     message: "请输入实际完成时长",
            //     trigger: "blur"
            //   }],
            //   type: "number",
            //   addDisplay:false,
            //   editDisplay:false
            // },
            {
              label: "作业说明",
              prop: "desc",
              type: "textarea",
              span: 24,
              minRows: 1,
              rules: [{
                required: true,
                message: "请输入作业说明",
                trigger: "blur"
              }],
              hide: true,
              maxlength:500,
              showWordLimit:true
            },
            {
              label: "作业附件1",
              prop: "jobArr1",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 1,
              data:{name:'file'},
              propsHttp: {
                url: 'url',
                name: 'name',
                // id:'id',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "作业附件2",
              prop: "jobArr2",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 1,
              data:{name:'file'},
              propsHttp: {
                url: 'url',
                name: 'name',
                // id:'id',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "作业附件3",
              prop: "jobArr3",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 1,
              data:{name:'file'},
              propsHttp: {
                url: 'url',
                name: 'name',
                // id:'id',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "作业附件4",
              prop: "jobArr4",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 1,
              data:{name:'file'},
              propsHttp: {
                url: 'url',
                name: 'name',
                // id:'id',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "作业附件5",
              prop: "jobArr5",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 1,
              data:{name:'file'},
              propsHttp: {
                url: 'url',
                name: 'name',
                // id:'id',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "作业附件6",
              prop: "jobArr6",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 1,
              data:{name:'file'},
              propsHttp: {
                url: 'url',
                name: 'name',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "答案附件1",
              prop: "answerArr1",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 1,
              propsHttp: {
                url: 'url',
                name: 'name',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "答案附件2",
              prop: "answerArr2",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 1,
              propsHttp: {
                url: 'url',
                name: 'name',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "答案附件3",
              prop: "answerArr3",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 6,
              propsHttp: {
                url: 'url',
                name: 'name',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "答案附件4",
              prop: "answerArr4",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 6,
              propsHttp: {
                url: 'url',
                name: 'name',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "答案附件5",
              prop: "answerArr5",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 6,
              propsHttp: {
                url: 'url',
                name: 'name',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            {
              label: "答案附件6",
              prop: "answerArr6",
              rules: [{
                required: false,
                message: "请上传附件",
                trigger: "blur"
              }],
              type: 'upload',
              loadText: '附件上传中，请稍等',
              limit: 6,
              propsHttp: {
                url: 'url',
                name: 'name',
                res: 'data'
              },
              fileSize: 10240,
              action: '/api/localfiles/UploadFileInRecord',
              hide: true
            },
            // {
            //   label: "作业附件1",
            //   prop: "pic1",
            //   rules: [{
            //     required: false,
            //     message: "请输入任务附件1",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业附件2",
            //   prop: "pic2",
            //   rules: [{
            //     required: false,
            //     message: "请输入任务附件2",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业附件3",
            //   prop: "pic3",
            //   rules: [{
            //     required: false,
            //     message: "请输入任务附件3",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业附件4",
            //   prop: "pic4",
            //   rules: [{
            //     required: false,
            //     message: "请输入任务附件4",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业附件5",
            //   prop: "pic5",
            //   rules: [{
            //     required: false,
            //     message: "请输入任务附件5",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业附件6",
            //   prop: "pic6",
            //   rules: [{
            //     required: false,
            //     message: "请输入任务附件6",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业答案1",
            //   prop: "answer_pic1",
            //   rules: [{
            //     required: false,
            //     message: "请输入作业答案1",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业答案2",
            //   prop: "answer_pic2",
            //   rules: [{
            //     required: false,
            //     message: "请输入作业答案2",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业答案3",
            //   prop: "answer_pic3",
            //   rules: [{
            //     required: false,
            //     message: "请输入作业答案3",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业答案4",
            //   prop: "answer_pic4",
            //   rules: [{
            //     required: false,
            //     message: "请输入作业答案4",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业答案5",
            //   prop: "answer_pic5",
            //   rules: [{
            //     required: false,
            //     message: "请输入作业答案5",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
            // {
            //   label: "作业答案6",
            //   prop: "answer_pic6",
            //   rules: [{
            //     required: false,
            //     message: "请输入作业答案6",
            //     trigger: "blur"
            //   }],
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   limit:1,
            //   listType: 'picture-img',
            //   span: 8,
            //   propsHttp: {
            //     url:'link',
            //     name:'name',
            //     res: 'data'
            //   },
            //   fileSize:500,
            //   action: '/api/kaibu-platform-service/oss/pri',
            //   tip: '只能上传jpg/png文件，且不超过500kb',
            //   hide: true
            // },
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission","JSuserInfo"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.job_add, false),
          viewBtn: this.vaildData(this.permission.job_view, false),
          delBtn: this.vaildData(this.permission.job_delete, false),
          editBtn: this.vaildData(this.permission.job_edit, false)
        };
      },
      // js_Id(){
      //   return this.JSuserInfo.js_Id
      // },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    mounted() {
      this.getSchoolTeacher()
      // var userinfo = getStore({
      //   name: "userInfo",
      // });
      // getBjTree({jsId:userinfo.relateId}).then(res => {
      //   this.treeData = res.data.data;
      // });
    },
    methods: {
      loadError(error){
        this.$message({
            type: "error",
            message: error
          });
      },
      nodeClick(data){
        this.treeBj = data.id;
        this.onLoad(this.page);
      },
      showJobRecords(row){
        this.jobId = row.id;
        this.showMain = false;
      },
      showMainView(){
        this.showMain = true;
      },
      // 保存
      rowSave(row, done, loading) {
        if (!contrastTime(row.startTime,row.endTime)) {
          this.$message({
            type: "warning",
            message: "开始时间不可大于结束时间!"
          });
          loading();
          return 0
        }
        row.id = "0"
        // row.JsId = this.js_Id
        // let newJobArr = []
        // let newAnswerArr = []
        // row.jobArr.forEach((item)=>{
        //   newJobArr.push(item.label)
        // })
        // row.answerArr.forEach((item)=>{
        //   newAnswerArr.push(item.label)
        // })
        row.jobArr = []
        row.answerArr = []
        let params = {
          filePath1:row.jobArr1.length>0?row.jobArr1[0].value:'',
          filePath2:row.jobArr2.length>0?row.jobArr2[0].value:'',
          filePath3:row.jobArr3.length>0?row.jobArr3[0].value:'',
          filePath4:row.jobArr4.length>0?row.jobArr4[0].value:'',
          filePath5:row.jobArr5.length>0?row.jobArr5[0].value:'',
          filePath6:row.jobArr6.length>0?row.jobArr6[0].value:'',
          filePath7:row.answerArr1.length>0?row.answerArr1[0].value:'',
          filePath8:row.answerArr2.length>0?row.answerArr2[0].value:'',
          filePath9:row.answerArr3.length>0?row.answerArr3[0].value:'',
          filePath610:row.answerArr4.length>0?row.answerArr4[0].value:'',
          filePath11:row.answerArr5.length>0?row.answerArr5[0].value:'',
          filePath12:row.answerArr6.length>0?row.answerArr6[0].value:'',
        }
        selectImgId(params).then((res)=>{
          if(res.data.data.filePath1 != null)  row.jobArr.push(res.data.data.filePath1)
          if(res.data.data.filePath2 != null)  row.jobArr.push(res.data.data.filePath2)
          if(res.data.data.filePath3 != null)  row.jobArr.push(res.data.data.filePath3)
          if(res.data.data.filePath4 != null)  row.jobArr.push(res.data.data.filePath4)
          if(res.data.data.filePath5 != null)  row.jobArr.push(res.data.data.filePath5)
          if(res.data.data.filePath6 != null)  row.jobArr.push(res.data.data.filePath6)
          if(res.data.data.filePath7 != null)  row.answerArr.push(res.data.data.filePath7)
          if(res.data.data.filePath8 != null)  row.answerArr.push(res.data.data.filePath8)
          if(res.data.data.filePath9 != null)  row.answerArr.push(res.data.data.filePath9)
          if(res.data.data.filePath10 != null)  row.answerArr.push(res.data.data.filePath10)
          if(res.data.data.filePath11 != null)  row.answerArr.push(res.data.data.filePath11)
          if(res.data.data.filePath12 != null)  row.answerArr.push(res.data.data.filePath12)
          this.submit(row,done, loading)
          console.log(row,row.jobArr,row.answerArr)
        })
      },
      submit(row,done, loading){
        add(row).then(() => {
          done();
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        }, error => {
          window.console.log(error);
          loading();
        });
      },
      rowUpdate(row, index, done, loading) {
        if (!contrastTime(row.startTime,row.endTime)) {
          this.$message({
            type: "warning",
            message: "开始时间不可大于结束时间!"
          });
          loading();
          return 0
        }
        let params = {}
        if(typeof row.jobArr1 == 'string'){
          params.filePath1 = row.jobArr1 == ''?'':row.jobArr1
        }else {
          params.filePath1 = row.jobArr1.length>0?row.jobArr1[0].value:''
        }
        if(typeof row.jobArr2 == 'string'){
          params.filePath2 = row.jobArr2 == ''?'':row.jobArr2
        }else {
          params.filePath2 = row.jobArr2.length>0?row.jobArr2[0].value:''
        }
        if(typeof row.jobArr3 == 'string'){
          params.filePath3 = row.jobArr3 == ''?'':row.jobArr3
        }else {
          params.filePath3 = row.jobArr3.length>0?row.jobArr3[0].value:''
        }
        if(typeof row.jobArr4 == 'string'){
          params.filePath4 = row.jobArr4 == ''?'':row.jobArr4
        }else {
          params.filePath4 = row.jobArr4.length>0?row.jobArr4[0].value:''
        }
        if(typeof row.jobArr5 == 'string'){
          params.filePath5 = row.jobArr5 == ''?'':row.jobArr5
        }else {
          params.filePath5 = row.jobArr5.length>0?row.jobArr5[0].value:''
        }
        if(typeof row.jobArr6 == 'string'){
          params.filePath6 = row.jobArr6 == ''?'':row.jobArr6
        }else {
          params.filePath6 = row.jobArr6.length>0?row.jobArr6[0].value:''
        }

        if(typeof row.answerArr1 == 'string'){
          params.filePath7 = row.answerArr1 == ''?'':row.answerArr1
        }else {
          params.filePath7 = row.answerArr1.length>0?row.answerArr1[0].value:''
        }
        if(typeof row.answerArr2 == 'string'){
          params.filePath8 = row.answerArr2 == ''?'':row.answerArr2
        }else {
          params.filePath8 = row.answerArr2.length>0?row.answerArr2[0].value:''
        }
        if(typeof row.answerArr3 == 'string'){
          params.filePath9 = row.answerArr3 == ''?'':row.answerArr3
        }else {
          params.filePath9 = row.answerArr3.length>0?row.answerArr3[0].value:''
        }
        if(typeof row.answerArr4 == 'string'){
          params.filePath10 = row.answerArr4 == ''?'':row.answerArr4
        }else {
          params.filePath10 = row.answerArr4.length>0?row.answerArr4[0].value:''
        }
        if(typeof row.answerArr5 == 'string'){
          params.filePath11 = row.answerArr5 == ''?'':row.answerArr5
        }else {
          params.filePath11 = row.answerArr5.length>0?row.answerArr5[0].value:''
        }
        if(typeof row.answerArr6 == 'string'){
          params.filePath12 = row.answerArr6 == ''?'':row.answerArr6
        }else {
          params.filePath12 = row.answerArr6.length>0?row.answerArr6[0].value:''
        }
        row.jobArr = []
        row.answerArr = []
        console.log('params',params)
        selectImgId(params).then((res)=>{
          if(res.data.data.filePath1 != null)  row.jobArr.push(res.data.data.filePath1)
          if(res.data.data.filePath2 != null)  row.jobArr.push(res.data.data.filePath2)
          if(res.data.data.filePath3 != null)  row.jobArr.push(res.data.data.filePath3)
          if(res.data.data.filePath4 != null)  row.jobArr.push(res.data.data.filePath4)
          if(res.data.data.filePath5 != null)  row.jobArr.push(res.data.data.filePath5)
          if(res.data.data.filePath6 != null)  row.jobArr.push(res.data.data.filePath6)
          if(res.data.data.filePath7 != null)  row.answerArr.push(res.data.data.filePath7)
          if(res.data.data.filePath8 != null)  row.answerArr.push(res.data.data.filePath8)
          if(res.data.data.filePath9 != null)  row.answerArr.push(res.data.data.filePath9)
          if(res.data.data.filePath10 != null)  row.answerArr.push(res.data.data.filePath10)
          if(res.data.data.filePath11 != null)  row.answerArr.push(res.data.data.filePath11)
          if(res.data.data.filePath12 != null)  row.answerArr.push(res.data.data.filePath12)
          this.updateSubmit(row,index,done, loading)
          console.log(row)
        })
      },
      updateSubmit(row,index,done, loading){
        update(row).then(() => {
          done();
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        }, error => {
          window.console.log(error);
          loading();
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove({ids:row.id});
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove({ids:this.ids});
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          // getDetail(this.form.id).then(res => {
          //   this.form = res.data.data;
          // });
        }
        if (["add"].includes(type)) {
          this.getSchoolTeacher()
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        console.log("params，",params)
         if(params.endTime!=undefined&&params.startTime==undefined){
          this.$message({
            type: "error",
            message: "开始时间有值时结束时间不能为空"
          });
          done();
          return;

        }else if(params.endTime==undefined&&params.startTime!=undefined){
          this.$message({
            type: "error",
            message: "开始时间有值时结束时间不能为空"
          });
          done();
          return;
        }
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      onLoad(page, params = {}) {
        this.loading = true;
        // params.JsId	 = this.js_Id;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });

        GradesByTeacher().then(res => {
          const column = this.findObject(this.option.column, "bjId");
          column.dicData = res.data.data;
        });
        CourseListByTeacher().then(res => {
          const column = this.findObject(this.option.column, "kcId");
          column.dicData = res.data.data;
        });
        GetWorkTypeList().then(res => {
          const column = this.findObject(this.option.column, "jobType");
          column.dicData = res.data.data;
        });
        // const school = this.findObject(this.option.column, "schoolId");
        // school.hide = true;
      },
      getSchoolTeacher() {
        getTeacherByRelateId().then(res => {
          this.form.schoolName = res.data.data.schoolName
          this.form.schoolId = res.data.data.schoolId
          this.form.jsName = res.data.data.jsName
          this.form.jsId = res.data.data.jsId
          console.log(res)
        });
      },
    }
  };
</script>

<style>
</style>
